#ifndef MYFILEWG_H
#define MYFILEWG_H

#include <QTimer>
#include <QWidget>
#include "common/common.h"

namespace Ui {
class myfilewg;
}

class myfilewg : public QWidget
{
    Q_OBJECT

public:
    explicit myfilewg(QWidget *parent = 0);
    ~myfilewg();

    void refreshFiles(Display cmd = Display::Normal);

    void clearAllTask();
private:
    void initListWidget();
    void addActionMenu();
    void checkTaskList();
    void addUploadFiles();
    void rightMenu(const QPoint& pos);
    QByteArray setGetCountJson(QString user, QString token);
    QStringList getCountStatus(QByteArray json);
    void clearFileList();

    void getUserFilesList(Display cmd = Display::Normal);
    void refreshFileItems();
    QByteArray setFilesListJson(QString user, QString token, int start, int count);
    QByteArray setDealFileJson(QString user, QString token, QString md5, QString filename);
    void getFileJsonInfo(QByteArray data);

    void clearItems();
    void addUploadItem(QString iconPath = ":/images/upload.png", QString name = "上传文件");

    void uploadFilesAction();
    void downloadFilesAction();
    void dealSelectdFile(QString cmd = "分享");

    //==========>分享文件<==============
    void shareFile(FileInfo *info); //分享某个文件

    //==========>删除文件<==============
    void delFile(FileInfo *info); //删除某个文件

    //==========>获取文件属性<==============
    void getFileProperty(FileInfo *info); //获取属性信息

    QByteArray setMd5Json(QString user, QString token, QString md5, QString fileName);

    void uploadFile(struct UploadFileInfo* info);

    void addDownloadFiles();

    void dealFilePv(QString md5, QString fileName);
signals:
    void gotoTransfer(TransferStatus state);
    void loginAgainSignal();
private:
    Ui::myfilewg *ui;
    class QNetworkAccessManager* m_manager;
    Common m_cm;

    class QMenu* m_menu;
    class QAction* m_downloadAction;
    QAction* m_shareAction;
    QAction* m_delAction;
    QAction* m_propertyAction;

    QMenu* m_menuEmpty;
    QAction* m_pvAscendingAction;
    QAction* m_pvDescendingAction;
    QAction* m_refreshAction;
    QAction* m_uploadAction;

    long m_userFilesCount;
    int m_start;
    int m_count;

    QTimer m_uploadFileTimer;   //定时检查上传队列是否有任务需要上传
    QTimer m_downloadTimer;     //定时检查下载队列是否有任务需要下载

    QList<FileInfo*> m_fileList;
};

#endif // MYFILEWG_H
